package com.nowcoder.chapter3.part39;

import java.io.*;

/**
 * 打印流
 */
public class IODemo7 {

    public static void main(String[] args) {
//        testPrintStream();
        testPrintWriter();
    }

    public static void testPrintStream() {
        try (
                FileOutputStream fos = new FileOutputStream("C:/work/alpha/a.txt");
                PrintStream ps = new PrintStream(fos);
        ) {
            ps.println("白日依山尽,");
            ps.println("黄河入海流.");
            ps.println("欲穷千里目,");
            ps.println("更上一层楼.");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void testPrintWriter() {
        try (
                FileWriter fw = new FileWriter("C:/work/alpha/b.txt");
                PrintWriter pw = new PrintWriter(fw);
        ) {
            pw.println("白日依山尽,");
            pw.println("黄河入海流.");
            pw.println("欲穷千里目,");
            pw.println("更上一层楼.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
